<script lang="ts" setup>
import { defineAsyncComponent } from 'vue';
import { storeToRefs } from 'pinia'
import useStore from "@/store"
const { main, user } = useStore();
const { getTodos, updateAllStatus } = main;
const { mainRadioStatus, renderList } = storeToRefs(main);
const { id } = storeToRefs(user);
const TodoItem = defineAsyncComponent(() => import("@/components/TodoItems.vue"))
const handleChangeAll = (done: boolean) => {
	updateAllStatus(id.value, done);
}
getTodos(id.value);
</script>
<template>
	<section class="main">
		<input id="toggle-all" @change="handleChangeAll(!mainRadioStatus)" :checked="mainRadioStatus" class="toggle-all"
			type="checkbox" />
		<label for="toggle-all">Mark all as complete</label>
		<ul class="todo-list">
			<todo-item v-for="item in renderList" :key="item.id" :user_id="id" :item="item"></todo-item>
		</ul>
	</section>
</template>

<style lang="scss" scoped>
.main {
	position: relative;
	z-index: 2;
	border-top: 1px solid #e6e6e6;

	label {
		cursor: pointer;
	}

	.toggle-all {
		width: 1px;
		height: 1px;
		border: none;
		/* Mobile Safari */
		opacity: 0;
		position: absolute;
		right: 100%;
		bottom: 100%;
	}

	.toggle-all+label {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 45px;
		height: 65px;
		font-size: 0;
		position: absolute;
		top: -65px;
		left: -0;
	}

	.toggle-all+label:before {
		content: '❯';
		display: inline-block;
		font-size: 22px;
		color: #949494;
		padding: 10px 27px 10px 27px;
		-webkit-transform: rotate(90deg);
		transform: rotate(90deg);
	}

	.toggle-all:checked+label:before {
		color: #484848;
	}

	.todo-list {
		margin: 0;
		padding: 0;
		list-style: none;
	}

	@media screen and (-webkit-min-device-pixel-ratio:0) {

		.toggle-all,
		.todo-list li .toggle {
			background: none;
		}

		.todo-list li .toggle {
			height: 40px;
		}
	}

	.toggle-all:focus+label {
		box-shadow: 0 0 2px 2px #CF7D7D;
		outline: 0;
	}
}
</style>